To display a file's image preview, your PreviewShowData function is called. Listing 2 includes the PICSPreviewShowData function, which previews a PICS file. The function loads the first PICT image from the PICS file and uses the PICT file preview component to display it.
Listing 2 Converting data into a form that can be displayed as a preview
pascal ComponentResult PICSPreviewShowData
(PICSPreviewGlobals store,
OSType dataType, Handle data,
const Rect *inHere)
{
OSErr err = noErr;
short resRef = 0, saveRes = CurResFile();
FSSpec theFile;
Boolean whoCares;
Handle thePict = nil;
ComponentInstance ci;
/* because your component has the pnotComponentNeedsNoCache
flag set, it should only be called to display files */
if (dataType != rAliasType)
return paramErr;
/* open up the file to preview */
if (err = ResolveAlias (nil, (AliasHandle)data, &theFile,
&whoCares)) goto bail;
resRef = FSpOpenResFile (&theFile, fsRdPerm);
if (err = ResError()) goto bail;
/* get the first 'PICT' */
UseResFile (resRef);
thePict = Get1IndResource ('PICT', 1);
if (!thePict) goto bail;
/* use the PICT preview component to display the preview */
if (ci = OpenDefaultComponent (ShowFilePreviewComponentType,
'PICT')) {
PreviewShowData (ci, 'PICT', thePict, inHere);
CloseComponent (ci);
}
bail:
if (resRef) CloseResFile (resRef);
if (thePict) DisposeHandle (thePict);
UseResFile (saveRes);
return err;
}